var t = getApp()
Page({
  data: {
    iconsUrl:t.globalData.iconsUrl,
    list:[],
    sort:['全部','本地服务','汽车用品','服装','文具','日用品'],
    sort_page:0,
    sort_show:false,
    loading:true,
    navHeight:t.globalData.navHeight,
    title:'积分商城',
  },
  onLoad: function (options) {
    if (t.globalData.show_login) {t.show_login();return;}
  },
  onShow(e){
    this.get_list()
  },
  onRefresh(){
    //在当前页面显示导航条加载动画
    wx.showNavigationBarLoading(); 
    //显示 loading 提示框。需主动调用 wx.hideLoading 才能关闭提示框
    this.get_list()
  },
  onPullDownRefresh: function () {
    //调用刷新时将执行的方法
    this.onRefresh();
    setTimeout(function () {
      // 不加这个方法真机下拉会一直处于刷新状态，无法复位
      wx.stopPullDownRefresh()
    }, 1000)
  },
  get_list(e){
    wx.showLoading({
      title: '加载中',
    })
    var that = this
    t.request('/goods/getList',{page:1},function(e){
      wx.hideLoading({
        success: (res) => {},
      })
      console.log(e);
      if (e.code==200) {
        that.setData({
          list:e.result.list,
          loading:false
        })
      }
    })
  },
  to_detail(e){
    if (t.globalData.show_login) {t.show_login();return;}
    var list = this.data.list
    var item 
    for (let i = 0; i < list.length; i++) {
      if (e.currentTarget.dataset.id==list[i].id) {
        item = list[i]
      }
    }
    wx.navigateTo({
      url: '/pages/pointMall/goodDetail/goodDetail?item=' + JSON.stringify(item),
    })
  },
  change_sort(e){
    if (t.globalData.show_login) {t.show_login();return;}
    wx.showToast({
      title: '暂未开放',
      icon:'none'
    })
    // this.setData({
    //   sort_page:e.currentTarget.dataset.page,
    //   sort_show:!this.data.sort_show
    // })
  },
})